package com.ruoyi.buss.group.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.buss.group.domain.DataCustomerGroup;
import com.ruoyi.buss.group.service.IDataCustomerGroupService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 客户群体配置Controller
 * 
 * @author sxy
 * @date 2021-07-16
 */
@Api(tags = {"群体controller"})
@RestController
@RequestMapping("/groupInfo")
public class DataCustomerGroupController extends BaseController
{
    @Autowired
    private IDataCustomerGroupService dataCustomerGroupService;

    /**
     * 查询客户群体配置列表
     */
    @ApiOperation(value="群体配置信息",notes="注意问题点")
    @PreAuthorize(hasPermi = "buss:groupInfo:list")
    @GetMapping("/listGroup")
    public TableDataInfo list(DataCustomerGroup dataCustomerGroup)
    {
        startPage();
        List<DataCustomerGroup> list = dataCustomerGroupService.selectDataCustomerGroupList(dataCustomerGroup);
        return getDataTable(list);
    }

    /**
     * 导出客户群体配置列表
     */
    @PreAuthorize(hasPermi = "buss:groupInfo:export")
    @Log(title = "客户群体配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataCustomerGroup dataCustomerGroup) throws IOException
    {
        List<DataCustomerGroup> list = dataCustomerGroupService.selectDataCustomerGroupList(dataCustomerGroup);
        ExcelUtil<DataCustomerGroup> util = new ExcelUtil<DataCustomerGroup>(DataCustomerGroup.class);
        util.exportExcel(response, list, "客户群体配置数据");
    }

    /**
     * 获取客户群体配置详细信息
     */
    @PreAuthorize(hasPermi = "buss:groupInfo:query")
    @GetMapping(value = "/{groupCode}")
    public AjaxResult getInfo(@PathVariable("groupCode") String groupCode)
    {
        return AjaxResult.success(dataCustomerGroupService.selectDataCustomerGroupById(groupCode));
    }

    /**
     * 新增客户群体配置
     */
    @PreAuthorize(hasPermi = "buss:groupInfo:add")
    @Log(title = "客户群体配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataCustomerGroup dataCustomerGroup)
    {
        return toAjax(dataCustomerGroupService.insertDataCustomerGroup(dataCustomerGroup));
    }

    /**
     * 修改客户群体配置
     */
    @PreAuthorize(hasPermi = "buss:groupInfo:edit")
    @Log(title = "客户群体配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataCustomerGroup dataCustomerGroup)
    {
        return toAjax(dataCustomerGroupService.updateDataCustomerGroup(dataCustomerGroup));
    }

    /**
     * 删除客户群体配置
     */
    @PreAuthorize(hasPermi = "buss:groupInfo:remove")
    @Log(title = "客户群体配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupCodes}")
    public AjaxResult remove(@PathVariable String[] groupCodes)
    {
        return toAjax(dataCustomerGroupService.deleteDataCustomerGroupByIds(groupCodes));
    }
}
